﻿#------------------------------------------------------------------------
#SHAREPOINT DEPLOYER V3.1 - DEVELOPED BY VENKATA HAREESH SANAGAVARAPU (harishmeetsu@gmail.com)
#----------------------------------------------

function OnApplicationLoad {
	write-host -ForegroundColor White "======================================"
	Write-Host -ForegroundColor Yellow "     Sharepoint Solution Deployer     "
	write-host -ForegroundColor White "======================================"
	Write-Host ""
	Write-Host ""
	Write-Host  -ForegroundColor DarkGreen "Please wait while the tool loads..."
	return $true 
}

function OnApplicationExit {
	
	$script:ExitCode = 0 
}

#endregion Application Functions

#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function Call-SharepointDeployer_pff {

	#----------------------------------------------
	#region Import the Assemblies
	#----------------------------------------------
	[void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
	[void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	[void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
	[void][reflection.assembly]::Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
	#endregion Import Assemblies

	#----------------------------------------------
	#region Generated Form Objects
	#----------------------------------------------
	[System.Windows.Forms.Application]::EnableVisualStyles()
	$formSharepointDeployerV3 = New-Object 'System.Windows.Forms.Form'
	$groupbox2 = New-Object 'System.Windows.Forms.GroupBox'
	$StatusUpdatebox1 = New-Object 'System.Windows.Forms.TextBox'
	$groupbox1 = New-Object 'System.Windows.Forms.GroupBox'
	$RetractWSPtextbox1 = New-Object 'System.Windows.Forms.TextBox'
	$checkboxRetractUsingADiffere = New-Object 'System.Windows.Forms.CheckBox'
	$buttonDeploy = New-Object 'System.Windows.Forms.Button'
	$checkboxTimerServiceRestart = New-Object 'System.Windows.Forms.CheckBox'
	$checkboxIISReset = New-Object 'System.Windows.Forms.CheckBox'
	$checkboxConfigFileChanges = New-Object 'System.Windows.Forms.CheckBox'
	$checkboxActivateFeatures = New-Object 'System.Windows.Forms.CheckBox'
	$checkboxDeploySolutions = New-Object 'System.Windows.Forms.CheckBox'
	$checkboxRetractSolutions = New-Object 'System.Windows.Forms.CheckBox'
	$checkboxDeActivateFeatures = New-Object 'System.Windows.Forms.CheckBox'
	$WSPtextbox1 = New-Object 'System.Windows.Forms.TextBox'
	$Featuretextbox1 = New-Object 'System.Windows.Forms.TextBox'
	$labelReadingTheWSPDetails = New-Object 'System.Windows.Forms.Label'
	$labelReadingTheFeatureDet = New-Object 'System.Windows.Forms.Label'
	$labelSharepointDeployer = New-Object 'System.Windows.Forms.Label'
	$RFCInputbox1 = New-Object 'System.Windows.Forms.GroupBox'
	$labelSelectTheEnvironment = New-Object 'System.Windows.Forms.Label'
	$EnvCombobox1 = New-Object 'System.Windows.Forms.ComboBox'
	$buttonApplyConfig = New-Object 'System.Windows.Forms.Button'
	$labelSelectTheApplication = New-Object 'System.Windows.Forms.Label'
	$labelPleaseProvideRFCNumb = New-Object 'System.Windows.Forms.Label'
	$AppNameCombobox1 = New-Object 'System.Windows.Forms.ComboBox'
	$CRNumbox1 = New-Object 'System.Windows.Forms.TextBox'
	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
	#endregion Generated Form Objects

	#----------------------------------------------
	# User Generated Script
	#----------------------------------------------
	
	
	function Decrypt-String($Encrypted)
	{
		[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
		if(Test-Path -Path ".\EncryptionTool\EncryptionConfig.xml")
		{
			[xml]$global:encryptionconfig = Get-Content -Path ".\EncryptionTool\EncryptionConfig.xml"
			$global:passPhrase=$encryptionconfig.configuration.passPhrase.value
			$global:saltValue=$encryptionconfig.configuration.saltValue.value
			$global:initVector=$encryptionconfig.configuration.initVector.value
		}
		else
		{
			write-host "EncryptionConfig.xml is missing"
			return "~"
		}
		if($Encrypted -is [string]){
			$Encrypted = [Convert]::FromBase64String($Encrypted)
	   	}
		$rij = new-Object System.Security.Cryptography.RijndaelManaged
		$pass = [Text.Encoding]::UTF8.GetBytes($passPhrase)
		$salt = [Text.Encoding]::UTF8.GetBytes($saltValue)
		$rij.Key = (new-Object Security.Cryptography.PasswordDeriveBytes $pass, $salt, "SHA1", 5).GetBytes(32) #256/8
		$rij.IV = (new-Object Security.Cryptography.SHA1Managed).ComputeHash( [Text.Encoding]::UTF8.GetBytes($initVector) )[0..15]
		$decryptor = $rij.CreateDecryptor()
		$memorystream = new-Object IO.MemoryStream @(,$Encrypted)
		$cryptostream = new-Object Security.Cryptography.CryptoStream $memorystream,$decryptor,"Read"
		$decryptedstream = new-Object IO.StreamReader $cryptostream
		Write-Output $decryptedstream.ReadToEnd()
		$decrypted=$decryptedstream.ReadToEnd()
		$decryptedstream.Close()
		$cryptostream.Close()
		$memorystream.Close()
		$rij.Clear()
		return $decrypted

	}
		
	
	$formSharepointDeployerV3_Load={
	
		if(Test-Path -Path ".\config.xml")
		{
			StatusUpdate("The configuration file, config.xml, is present in the local directory.")
			[xml]$config=Get-Content -Path ".\config.xml"
			
			foreach ($environment in $config.SHAREPOINT_CONFIGURATION.ENVIRONMENT) 
			{
				$EnvCombobox1.Items.Add($environment.EnvName)
			}
		}
		else
		{
			StatusUpdate("config.xml is missing")
		}
		
	}
	#region Control Helper Functions
	function Load-ComboBox 
	{
	<#
		.SYNOPSIS
			This functions helps you load items into a ComboBox.
	
		.DESCRIPTION
			Use this function to dynamically load items into the ComboBox control.
	
		.PARAMETER  ComboBox
			The ComboBox control you want to add items to.
	
		.PARAMETER  Items
			The object or objects you wish to load into the ComboBox's Items collection.
	
		.PARAMETER  DisplayMember
			Indicates the property to display for the items in this control.
		
		.PARAMETER  Append
			Adds the item(s) to the ComboBox without clearing the Items collection.
		
		.EXAMPLE
			Load-ComboBox $combobox1 "Red", "White", "Blue"
		
		.EXAMPLE
			Load-ComboBox $combobox1 "Red" -Append
			Load-ComboBox $combobox1 "White" -Append
			Load-ComboBox $combobox1 "Blue" -Append
		
		.EXAMPLE
			Load-ComboBox $combobox1 (Get-Process) "ProcessName"
	#>
		Param (
			[ValidateNotNull()]
			[Parameter(Mandatory=$true)]
			[System.Windows.Forms.ComboBox]$ComboBox,
			[ValidateNotNull()]
			[Parameter(Mandatory=$true)]
			$Items,
		    [Parameter(Mandatory=$false)]
			[string]$DisplayMember,
			[switch]$Append
		)
		
		if(-not $Append)
		{
			$ComboBox.Items.Clear()	
		}
		
		if($Items -is [Object[]])
		{
			$ComboBox.Items.AddRange($Items)
		}
		elseif ($Items -is [Array])
		{
			$ComboBox.BeginUpdate()
			foreach($obj in $Items)
			{
				$ComboBox.Items.Add($obj)	
			}
			$ComboBox.EndUpdate()
		}
		else
		{
			$ComboBox.Items.Add($Items)	
		}
	
		$ComboBox.DisplayMember = $DisplayMember	
	}#endregion
	
	$buttonApplyConfig_Click={
			if($CRNumbox1.Text -eq "")
			{
				StatusUpdate("PLEASE ENTER THE RFC NUMBER")
				[System.Windows.Forms.Application]::DoEvents()
				return
			}
			elseif($EnvCombobox1.Text -eq "")
			{
				StatusUpdate("PLEASE SELECT VALID ENVIRONMENT")
				[System.Windows.Forms.Application]::DoEvents()
				return
			}
			elseif($AppNameCombobox1.Text -eq "")
			{
				StatusUpdate("PLEASE SELECT VALID APPLICATION")
				[System.Windows.Forms.Application]::DoEvents()
				return
			}
			else
			{
				$global:RFCNumber=$CRNumbox1.Text
				$global:Application=$AppNameCombobox1.Text
				$global:Environment=$EnvCombobox1.Text
				[xml]$global:configxml=Get-Content -Path ".\config.xml"
				ForEach($env in $configxml.SHAREPOINT_CONFIGURATION.ENVIRONMENT|Where-Object{$_.EnvName -eq $EnvCombobox1.Text}) 
				{
					$global:domain=$env.DOMAIN
					$global:farmusername=$env.FARM_ADMIN_USERNAME
					$global:farmpasswdenc=$env.FARM_ADMIN_PASSWORD
					$global:farmservers=$env.SERVERS_IN_CSV
					$global:servers=$farmservers.Split(",")
					$global:logspath=$env.LOGS_PATH
					$global:hivebinpath=$env.HIVE_BIN_PATH
					$global:SolutionsCA=$env.SOLUTIONS_URL
					foreach($app in $env.APPLICATION.NAME|Where-Object{$_.AppName -eq $AppNameCombobox1.Text})
					{
						$global:deploymentwsppath=$app.DEPLOYMENT_WSP_BASE_PATH
						$global:appurl=$app.APP_URL
						$global:appSCFeaturesURL=$app.SITECOLLECTIONFEATURES_URL
						$global:appVDir=$app.VIRTUAL_DIRECTORY
					}
				}
				$groupbox1.Enabled=$true
				$Featuretextbox1.Text=$deploymentwsppath+"\"+$RFCNumber+"_Features.txt"
				$WSPtextbox1.Text=$deploymentwsppath+"\"+$RFCNumber+"_WSPList.txt"
				$RetractWSPtextbox1.Text=$deploymentwsppath+"\"+$RFCNumber+"_retract_WSPList.txt"
				#[string]$global:decryptedpassword=Invoke-Command -ScriptBlock {.\EncryptionTool\Utilities.Encryption.Cmd.exe /D $farmpasswdenc}
				[string]$global:decryptedpassword=Decrypt-String $farmpasswdenc
				if($decryptedpassword -ne "~")
				{
					$decryptedpassword.trim()
					if($decryptedpassword.EndsWith(" "))
					{
						$decryptedpassword=$decryptedpassword.SubString(0,$decryptedpassword.Length-1)
					}
				}
				else
				{
					StatusUpdate("EncryptionConfig.xml is missing in the .\EncryptionTool folder.")
					return
				}
				StatusUpdate("Applied the configuration for the selected parameters.")
				StatusUpdate("Check if the input text files are the right ones to be used.")
				[System.Windows.Forms.Application]::DoEvents()
			}
	}
	
	$buttonDeploy_Click={
			$groupbox1.Enabled=$false
			$RFCInputbox1.Enabled=$false
			$flag = doValidations
			if($flag -ne $true)
			{
				$groupbox1.Enabled=$true
				$RFCInputbox1.Enabled=$true
				return
			}
			else
			{
				if($checkboxDeActivateFeatures.Checked -eq $true)
				{
					$check=DeActivateFeature
					if($check -eq $false)
					{
						$groupbox1.Enabled=$true
						$RFCInputbox1.Enabled=$true
						return
					}
					else
					{
						Write-Host "Features Deactivated"
					}
				}
				if($checkboxRetractSolutions.Checked -eq $true)
				{
					$check=RetractSolution
					if($check -eq $false)
					{
						$groupbox1.Enabled=$true
						$RFCInputbox1.Enabled=$true
						return
					}
					else
					{
						Write-Host "Solutions Retracted"
					}
				}
				if($checkboxDeploySolutions.Checked -eq $true)
				{
					$check=DeploySolution
					if($check -eq $false)
					{
						$groupbox1.Enabled=$true
						$RFCInputbox1.Enabled=$true
						return
					}
					else
					{
						Write-Host "Solutions Deployed"
					}
				}
				if($checkboxActivateFeatures.Checked -eq $true)
				{
					$check=ActivateFeatures
					if($check -eq $false)
					{
						$groupbox1.Enabled=$true
						$RFCInputbox1.Enabled=$true
						return
					}
					else
					{
						Write-Host "Features Activated"
					}
				}
				if($checkboxConfigFileChanges.Checked -eq $true)
				{
					do
					{
						$check=ConfigFileChanges
						#StatusUpdate "Checking value is $check"
						#Write-Host "$check"
						if($check -eq "OK True")
						{
							break
						}
					}while($check -ne "OK False")
					Write-Host "Config Changes complete"
				}
				if($checkboxIISReset.Checked -eq $true)
				{
					$check=IISResets
					if($check -eq $false)
					{
						$groupbox1.Enabled=$true
						$RFCInputbox1.Enabled=$true
						return
					}
					else
					{
						Write-Host "IIS Resets Complete"
					}
				}
				if($checkboxTimerServiceRestart.Checked -eq $true)
				{
					$check=TimerRestart
					if($check -eq $false)
					{
						$groupbox1.Enabled=$true
						$RFCInputbox1.Enabled=$true
						return
					}
					else
					{
						Write-Host "Timer Restarts Complete"
					}
				}
				StatusUpdate("Execution Complete!!")
				$groupbox1.Enabled=$true
				$RFCInputbox1.Enabled=$true
				return
			}
			get-pssession|remove-pssession
	}

	function TimerRestart
	{
		StatusUpdate("Restarting Timer services on all the farm servers.")
		[System.Windows.Forms.Application]::DoEvents()
		$timerrestartjobname="TimerRestarts_"+(Get-Date -Format hh:mm:ss)
		$timerrestartjobname=[string]$timerrestartjobname
		foreach($server in $servers)
		{
			$timerrestartjob=Invoke-Command -Session $session -ScriptBlock {param($server);Restart-Service -InputObject $(Get-Service -Computer $server -Name SPTimerV4)} -ArgumentList $server -AsJob -JobName $timerrestartjobname
			while($timerrestartjob.State)
			{
				if($timerrestartjob.State -eq "Completed")
				{
					StatusUpdate("Timer Service restart complete on $server.")
					[System.Windows.Forms.Application]::DoEvents()
					break
				}
				elseif ($timerrestartjob.State -eq "Failed") 
				{
					$timerreceivedstatus=Receive-Job -Name $timerrestartjobname
					StatusUpdate("TIMER SERVICE RESTART FAILED ON $server. ERROR IS $timerreceivedstatus")
					[System.Windows.Forms.Application]::DoEvents()
					break
				}
				else
				{
					StatusUpdate("Completing Timer restart on $server...")
					[System.Windows.Forms.Application]::DoEvents()
					Start-Sleep -Seconds 2
					continue
				}
			}
		}
		
		return $true
	}
	function IISResets
	{
		StatusUpdate("Completing IIS Resets..")
		[System.Windows.Forms.Application]::DoEvents()
		#Write-Host $servers
		$iisresetjobname="IISResets_"+(Get-Date -Format hh:mm:ss)
		$iisresetjobname=[string]$iisresetjobname
		foreach($server in $servers)
		{
			$jobiisreset=Invoke-Command -Session $session -ScriptBlock{param($server);iisreset $server} -ArgumentList $server -AsJob -JobName $iisresetjobname
			while($jobiisreset.State)
			{
				if($jobiisreset.State -eq "Completed")
				{
					StatusUpdate("IIS Reset complete on $server.")
					[System.Windows.Forms.Application]::DoEvents()
					break
				}
				elseif($jobiisreset.State -eq "Failed")
				{
					$iisresetjobrecevied=Receive-Job -Name $iisresetjobname
					StatusUpdate("IIS RESET ON THE SERVER $server FAILED WITH ERROR $iisresetjobrecevied .")
					[System.Windows.Forms.Application]::DoEvents()
					#return $false
					break
				}
				else
				{
					StatusUpdate("Completing IIS Reset on $server...")
					[System.Windows.Forms.Application]::DoEvents()
					Start-Sleep -Seconds 2
					continue
				}
			}
		}
		return $true				
	}
	function ConfigFileChanges
	{
		StatusUpdate("Waiting for the user to complete Config file changes...")
		[System.Windows.Forms.Application]::DoEvents()
		[System.Windows.Forms.MessageBox]::Show("It is opted to complete the configuration changes in the farm servers before continuing further.`n`n Please click OK when you want to continue.", "Configuration Changes")
		if(([System.Windows.Forms.MessageBox]::Show("Do you really want to continue with steps after Configuration changes?", "Confirmation",[System.Windows.Forms.MessageBoxButtons]::YesNo,[System.Windows.Forms.MessageBoxIcon]::Question)) -eq "YES")
		{
			#Write-Host "Into true condition"
			return $true
		}
		else
		{
			#Write-Host "Into false condition"
			return $false
		}	
	}
	function ActivateFeatures
	{
		StatusUpdate("Activating Features...")
		[System.Windows.Forms.Application]::DoEvents()
		$jobname="ListFeaturesTxtFile_"+(Get-Date -Format hh:mm:ss)
		$jobname=[string]$jobname
		#Write-Host $jobname
		$joblistfeatures=Invoke-Command -Session $session -ScriptBlock {param($featurestxtfilepath) Get-Content -Path $featurestxtfilepath} -ArgumentList $featurestxtfilepath -AsJob -JobName $jobname
		while($joblistfeatures.State)
		{
			if($joblistfeatures.State -eq "Completed")
			{
				$listoffeatures=Receive-Job -Name $jobname
				break
			}
			elseif($joblistfeatures.State -eq "Failed")
			{
				StatusUpdate("UNABLE TO GET THE LIST OF FEATURES TO BE ACTIVATED.")
				[System.Windows.Forms.Application]::DoEvents()
				return $false
			}
			else
			{
				StatusUpdate("Getting the list of features to be activated...please wait...")
				[System.Windows.Forms.Application]::DoEvents()
				Start-Sleep -Seconds 1
				continue
			}
		}	
		if($listoffeatures)
		{
			foreach($featureentry in $listoffeatures)
			{
				$featurearray=$featureentry.Split(",")
				$feature=$featurearray[0]
				$feature=[string]$feature
				if($featurearray[1])
				{
					$tempurl=$appurl
					$appurl=$featurearray[1]
				}
				#Write-Host $feature
				#Write-Host $appurl
				#write-host $tempurl
				StatusUpdate("Activating Feature $feature ...")
				[System.Windows.Forms.Application]::DoEvents()
				if($feature.Length -ge 1)
				{
					$jobname="EnableFeature_"+(Get-Date -Format hh:mm:ss)
					$jobname=[string]$jobname				
					$activatejob=Invoke-Command -Session $session -ScriptBlock{param($feature,$appurl) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; enable-spfeature -identity $feature -url $appurl -confirm:$false -force} -ArgumentList $feature,$appurl -AsJob -JobName $jobname
				}
				else
				{
					Continue
				}
				while($activatejob.State)
				{
					if($activatejob.State -eq "Completed")
					{
						StatusUpdate("Invoked the Feature Activation command, checking if this is a success...")
						[System.Windows.Forms.Application]::DoEvents()
						Remove-Job $activatejob
						break
					}
					elseif($activatejob.State -eq "Failed")
					{
						$Activatejobreceived=Receive-Job -Name $jobname
						StatusUpdate("ACTIVATION JOB FAILED. PLEASE ACTIVATE MANUALLY.")
						StatusUpdate("IF IT IS A SITECOLLECTION FEATURE, THE URL IS $appSCFeaturesURL. ERROR IS $Activatejobreceived")
						[System.Windows.Forms.Application]::DoEvents()
						return $false
					}
					else
					{
						StatusUpdate("Activating feature....please wait...")
						[System.Windows.Forms.Application]::DoEvents()
						Start-Sleep -Seconds 1
						Continue
					}
				}
				$scopejobname="GetScopeJob_"+(Get-Date -Format hh:mm:ss)
				$scopejobname=[string]$scopejobname
				$scopejob=Invoke-Command -Session $session -ScriptBlock{param($feature) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; (Get-SpFeature -Identity $feature).Scope} -ArgumentList $feature -AsJob -JobName $scopejobname
				while($scopejob.State)
				{
					if($scopejob.State -eq "Completed")
					{
						$scope=Receive-Job -Name $scopejobname
						Remove-Job $scopejobname
						break
					}
					elseif($scopejob.State -eq "Failed")
					{
						$scope=Receive-Job -Name $scopejobname
						StatusUpdate("COULD NOT GET THE STATUS OF THE FEATURE AFTER ACTIVATION. PLEASE CHECK $appSCFeaturesURL IF IT IS A SITE COLLECTION FEATURE. ERROR is $scope .")
						[System.Windows.Forms.Application]::DoEvents()
						return $false
					}
					else
					{
						StatusUpdate("Checking if the feature is activated...please wait...")
						[System.Windows.Forms.Application]::DoEvents()
						Start-Sleep -Seconds 1
						Continue
					}
				}
				$jobname="CheckFeature_"+(Get-Date -Format hh:mm:ss)
				$jobname=[string]$jobname
				$scope=[string]$scope
				#Write-Host $scope
				if(($scope -eq "Farm") -or ($scope -eq "0"))
				{
					StatusUpdate("Feature $feature is scoped to the Farm")
					[System.Windows.Forms.Application]::DoEvents()
					$checkfeaturejob=Invoke-Command -Session $session -ScriptBlock{param($feature) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; Get-SPFeature -Identity $feature -ErrorAction SilentlyContinue -Farm  } -ArgumentList $feature -AsJob -JobName $jobname
				}
				elseif(($scope -eq "WebApplication") -or ($scope -eq "1"))
				{
					StatusUpdate("Feature $feature is scoped to the WebApplication.")
					[System.Windows.Forms.Application]::DoEvents()
					$checkfeaturejob=Invoke-Command -Session $session -ScriptBlock{param($feature, $appurl) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; Get-SPFeature -Identity $feature -ErrorAction SilentlyContinue -WebApplication $appurl  } -ArgumentList $feature,$appurl -AsJob -JobName $jobname
				}
				elseif(($scope -eq "Site") -or ($scope -eq "2"))
				{
					StatusUpdate("Feature $feature is scoped to the SiteCollection.")
					[System.Windows.Forms.Application]::DoEvents()				
					$checkfeaturejob=Invoke-Command -Session $session -ScriptBlock{param($feature, $appurl) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; Get-SPFeature -Identity $feature -ErrorAction SilentlyContinue -Site $appurl  } -ArgumentList $feature,$appurl -AsJob -JobName $jobname
				}
				elseif(($scope -eq "Web") -or ($scope -eq "3"))
				{
					StatusUpdate("Feature $feature is scoped to the Site.")
					[System.Windows.Forms.Application]::DoEvents()		
					$checkfeaturejob=Invoke-Command -Session $session -ScriptBlock{param($feature, $appurl) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; Get-SPFeature -Identity $feature -ErrorAction SilentlyContinue -Web $appurl  } -ArgumentList $feature,$appurl -AsJob -JobName $jobname
				}
				else
				{
					StatusUpdate("COULD NOT GET THE SCOPE THE FEATURE TO VERIFY IF IT IS ACTIVATED. PLEASE CHECK MANUALLY $appSCFeaturesURL")
					[System.Windows.Forms.Application]::DoEvents()
					return $false
				}
				while($checkfeaturejob.State)
				{
					if($checkfeaturejob.State -eq "Completed")
					{
						$activatedfeaturecheck=Receive-Job -Name $jobname
						Remove-Job $checkfeaturejob
						break
					}
					elseif($checkfeaturejob.State -eq "Failed")
					{
						StatusUpdate("COULD NOT GET THE STATUS OF THE FEATURE AFTER ACTIVATION. PLEASE CHECK $appSCFeaturesURL")
						[System.Windows.Forms.Application]::DoEvents()
						return $false
					}
					else
					{
						StatusUpdate("Checking if the feature is activated...please wait...")
						[System.Windows.Forms.Application]::DoEvents()
						Start-Sleep -Seconds 1
						Continue
					}
				}
				$activatedfeaturecheckname=[string]$activatedfeaturecheck.DisplayName
				$activatedfeaturecheckID=[string]$activatedfeaturecheck.Id
				if($activatedfeaturecheckname -eq "")
				{
					StatusUpdate("FEATURE $feature IS NOT ACTIVATED. PLEASE CHECK MANUALLY AT  $appSCFeaturesURL ")
					[System.Windows.Forms.Application]::DoEvents()
					return $false
				}
				elseif(($activatedfeaturecheckname -eq $feature) -or ($activatedfeaturecheckID -eq $feature))
				{
					StatusUpdate("Feature $feature is activated successfully.")
					[System.Windows.Forms.Application]::DoEvents()
				}
				else
				{
					StatusUpdate("FEATURE THAT DIDNOT GET ACTIVATED $feature")
					StatusUpdate("$activatedfeaturecheck")
					[System.Windows.Forms.Application]::DoEvents()
					return $false
				}
			}
		}
		else
		{
			StatusUpdate("THE ACTIVATION FEATURE FUNCTION DID NOT SUCCEED AS THERE ARE NO FEATURES LISTED IN THE FEATURES TXT FILE.")
			[System.Windows.Forms.Application]::DoEvents()
			return $false
		}
		$appurl=$tempurl
		#write-host $appurl
		return $true
	}
	function DeploySolution()
	{
		StatusUpdate("Deploying Solutions...")
		[System.Windows.Forms.Application]::DoEvents()
		foreach($line in $DeployWSPList)
		{
			$scopeURL=""
			if($line.Length -ge 2)
			{
				$splitline=$line.Split(",")
				$wsp=$splitline[0]
				if($splitline.Length -gt 1)
				{
					$splitline[1]=[string]$splitline[1]
					$scopeURL=$splitline[1].Trim()
				}
				$wsp=[string]$wsp
				if($wsp.EndsWith(".wsp"))
				{
				}
				else
				{
					$wsp=$wsp+".wsp"
				}
				StatusUpdate("$wsp is a WSP to be a deployed. Checking the status of this wsp..")
				[System.Windows.Forms.Application]::DoEvents()
				$checkWSPstatusjobname="CheckWSPStatus_"+(Get-Date -Format hh:mm:ss)
				$checkWSPstatusjobname=[String]$checkWSPstatusjobname
				$wspStatus=""
				$checkWSPstatusjob=Invoke-Command -Session $session -ScriptBlock {param($wsp);Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ;$wspStatus=Get-SPSolution | Where-Object {$_.Name -eq $wsp};$wspStatus.Deployed} -ArgumentList $wsp -AsJob -JobName $checkWSPstatusjobname
				while($checkWSPstatusjob.State)
				{
					if($checkWSPstatusjob.State -eq "Completed")
					{
						$wspStatus=Receive-Job -Name $checkWSPstatusjobname
						Remove-Job -Name $checkWSPstatusjobname
						break
					}
					elseif($checkWSPstatusjob.State -eq "Failed")
					{
						$wspStatus=Receive-Job -Name $checkWSPstatusjobname
						StatusUpdate("THERE IS AN ERROR WHILE CHECKING STATUS OF THE SOLUTION $wsp TO THE STORE. ERROR is $wspStatus")
						[System.Windows.Forms.Application]::DoEvents()
						return $false
					}
					else
					{
						StatusUpdate("Checking the status of the wsp...please wait...")
						[System.Windows.Forms.Application]::DoEvents()
						Start-Sleep -Seconds 2
						Continue
					}
				}
				if(!$wspStatus)
				{
					StatusUpdate("$wsp is absent in the solution store. Continuing with the installation and deployment..")
					[System.Windows.Forms.Application]::DoEvents()
					$addSolutionjobname="AddSolution_"+(Get-Date -Format hh:mm:ss)
					$addSolutionjobname=[string]$addSolutionjobname
					$wsppath=$deploymentwsppath+"\"+$wsp
					$addsolutionjob=Invoke-Command -Session $session -ScriptBlock {param($wsppath);;Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue;Add-SPSolution -LiteralPath $wsppath} -ArgumentList $wsppath -AsJob -JobName $addSolutionjobname
					while($addsolutionjob.State)
					{
						if($addsolutionjob.State -eq "Completed")
						{
							$wspStatusAfterAddition=Receive-Job -Name $addSolutionjobname
							if(!$wspStatusAfterAddition.Deployed)
							{
								StatusUpdate("Solution $wsp is added to the farm solution store.")
								[System.Windows.Forms.Application]::DoEvents()
								break
							}
							else
							{
								StatusUpdate("THERE IS AN ERROR WHILE ADDING THE SOLUTION TO THE STORE.PLEASE CHECK MANUALLY AT $SolutionsCA ")
								[System.Windows.Forms.Application]::DoEvents()
								return $false
							}
						}
						elseif($addsolutionjob.State -eq "Failed")
						{
							$wspStatusAfterAddition=Receive-Job -Name $addSolutionjobname
							StatusUpdate("THERE IS AN ERROR WHILE ADDING THE SOLUTION $wsp TO THE STORE. THE ERROR IS  $wspStatusAfterAddition")
							[System.Windows.Forms.Application]::DoEvents()
							return $false
						}
						else
						{
							StatusUpdate("Adding the solution $wsp to the farm...please wait..")
							[System.Windows.Forms.Application]::DoEvents()
							Start-Sleep -Seconds 2
							Continue
						}
					}
					$deploysolutionjobname="DeploySolution_"+(Get-Date -Format hh:mm:ss)
					$deploysolutionjobname=[string]$deploysolutionjobname
					$deploysolutionjob=Invoke-Command -Session $session -ScriptBlock {param($wsppath,$scopeURL,$wsp);Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue;$solution=Get-SPSolution | Where-Object {($_.Name -eq $wsp)};if(!$solution.ContainsWebApplicationResource){Install-SPSolution -identity $wsp -GACDeployment -Confirm:$false;} else{if($scopeURL.StartsWith("http")){ install-SPSolution -identity $solution.SolutionId -WebApplication $scopeURL -GACDeployment -Force} else{ Install-SPSolution -identity $solution.SolutionID -AllWebApplications -GACDeployment -Force}};while($solution.JobExists){Start-Sleep -Seconds 2}} -ArgumentList $wsppath,$scopeURL,$wsp -AsJob -JobName $deploySolutionjobname
					while($deploysolutionjob.State)
					{
						if($deploysolutionjob.State -eq "Completed")
						{
							StatusUpdate("Installation and Deployment of $wsp is complete. Checking if the WSP is still absent in the store.")
							[System.Windows.Forms.Application]::DoEvents()
							$checkWSPstatusjobname="CheckWSPStatus_"+(Get-Date -Format hh:mm:ss)
							$checkWSPstatusjobname=[String]$checkWSPstatusjobname
							$checkWSPstatusjob=Invoke-Command -Session $session -ScriptBlock {param($wsp);Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ;$wspStatus=Get-SPSolution | Where-Object {$_.Name -eq $wsp};$wspStatus.LastOperationResult} -ArgumentList $wsp -AsJob -JobName $checkWSPstatusjobname
							while($checkWSPstatusjob.State)
							{
								if($checkWSPstatusjob.State -eq "Completed")
								{
									$wspStatusAfterDeployment=Receive-Job -Name $checkWSPstatusjobname
									Remove-Job -Name $checkWSPstatusjobname
									break
								}
								elseif($checkWSPstatusjob.State -eq "Failed")
								{
									StatusUpdate("UNABLE TO GET THE STATUS OF WSP. PLEASE CHECK MANUALLY AT $SolutionsCA  .")
									return $false
								}
								else
								{
									StatusUpdate("Checking the status of wsp in the store...please wait...")
									[System.Windows.Forms.Application]::DoEvents()
									Start-Sleep -Seconds 1
									Continue
								}
									
							}
							$wspStatusAfterDeployment=[string]$wspStatusAfterDeployment
							if(!$wspStatusAfterDeployment)
							{
								StatusUpdate("DEPLOYMENT FAILED. $wsp IS STILL ABSENT IN THE FARM AFTER DEPLOYMENT. PLEASE CHECK $SolutionsCA . $wspStatusAfterDeployment")
								[System.Windows.Forms.Application]::DoEvents()
								return $false
							}
							elseif($wspStatusAfterDeployment -like "*Fail*")
							{
								StatusUpdate("THERE IS AN ERROR IN THE WSP DEPLOYMENT. THE ERROR IS $wspStatusAfterDeployment .PLEASE CHECK $SolutionsCA .")
								[System.Windows.Forms.Application]::DoEvents()
								return $false
							}
							elseif($wspStatusAfterDeployment -eq 2)
							{
								StatusUpdate("Deployment Successful. $wsp is installed and deployed.")
								[System.Windows.Forms.Application]::DoEvents()
								break
							}
							elseif($wspStatusAfterDeployment -eq 7)
							{
								StatusUpdate("THERE IS AN ERROR IN THE WSP DEPLOYMENT. THE ERROR CODE IS $wspStatusAfterDeployment .PLEASE CHECK $SolutionsCA .")
								[System.Windows.Forms.Application]::DoEvents()
								return $false
							}
							else
							{
								StatusUpdate("SOME ERROR IN DEPLOYMENT. $wspStatusAfterDeployment . PLEASE CHECK $SolutionsCA .")
								[System.Windows.Forms.Application]::DoEvents()
								return $false
							}
						}
						elseif($deploysolutionjob.State -eq "Failed")
						{
							$deploysolutionjobreceived=Receive-Job -Name $deploysolutionjobname
							StatusUpdate("DEPLOY SOLUTIONS JOB FAILED. PLEASE CHECK IF THE WSPs ARE ADDED AT $SolutionsCA . $deploysolutionjobreceived")
							[System.Windows.Forms.Application]::DoEvents()
							return $false
						}
						else
						{
							StatusUpdate("Deployment under progress..please wait..")
							[System.Windows.Forms.Application]::DoEvents()
							Start-Sleep -Seconds 4
							Continue
						}
					}
				}
				else
				{
					StatusUpdate("$wsp IS PRESENT IN THE SOLUTION STORE. CANNOT PROCEED WITH DEPLOYMENT PROCEDURE. PLEASE CHECK $SolutionsCA .")
					[System.Windows.Forms.Application]::DoEvents()
					return $false
				}
			}
		}
		return $true
	}
	function RetractSolution()
	{
		StatusUpdate("Retracting Solutions...")
		[System.Windows.Forms.Application]::DoEvents()
		$retractwsplistjobname="ListWSPsRetraction_"+(Get-Date -Format hh:mm:ss)
		$retractwsplistjobname=[string]$retractwsplistjobname
		StatusUpdate("Getting the list of WSPs to be retracted...")
		[System.Windows.Forms.Application]::DoEvents()
		if($checkboxRetractUsingADiffere.Checked -eq $true)
		{
			$retractwsplistjob=Invoke-Command -Session $session -ScriptBlock{param($retractwsptxtfilepath);Get-Content -Path $retractwsptxtfilepath} -ArgumentList $retractwsptxtfilepath -AsJob -JobName $retractwsplistjobname
		}
		else
		{
			$retractwsptxtfilepath=$WSPtextbox1.Text
			$retractwsplistjob=Invoke-Command -Session $session -ScriptBlock{param($retractwsptxtfilepath);Get-Content -Path $retractwsptxtfilepath} -ArgumentList $retractwsptxtfilepath -AsJob -JobName $retractwsplistjobname
		}
		while($retractwsplistjob.State)
		{
			If($retractwsplistjob.State -eq "Completed")
			{
				$retractwsplist=Receive-Job -Name $retractwsplistjobname
				Remove-Job -Name $retractwsplistjobname
				break
			}
			elseif($retractwsplistjob.State -eq "Failed")
			{
				StatusUpdate("COULD NOT GET THE LIST OF WSPS TO BE RETRACTED.")
				[System.Windows.Forms.Application]::DoEvents()
				return $false
			}
			else
			{
				StatusUpdate("Getting the list of WSPs to be retracted...")
				[System.Windows.Forms.Application]::DoEvents()
				Start-Sleep -Seconds 1
				continue
			}
		}
		foreach($line in $retractwsplist)
		{
			if($line.Length -ge 2)
			{
				$splitline=$line.Split(",")
				$wsp=$splitline[0]
				if($splitline.Length -gt 1)
				{
					$splitline[1]=[string]$splitline[1]
					$scopeURL=$splitline[1].Trim()
				}
				$wsp=[string]$wsp
				if($wsp.EndsWith(".wsp"))
				{
				}
				else
				{
					$wsp=$wsp+".wsp"
				}
				StatusUpdate("$wsp is a WSP to be a retracted. Checking the status of this wsp..")
				[System.Windows.Forms.Application]::DoEvents()
				$checkWSPstatusjobname="CheckWSPStatus_"+(Get-Date -Format hh:mm:ss)
				$checkWSPstatusjobname=[String]$checkWSPstatusjobname
				$checkWSPstatusjob=Invoke-Command -Session $session -ScriptBlock {param($wsp);Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ;$wspStatus=Get-SPSolution | Where-Object {$_.Name -eq $wsp};$wspStatus.Deployed} -ArgumentList $wsp -AsJob -JobName $checkWSPstatusjobname
				while($checkWSPstatusjob.State)
				{
					if($checkWSPstatusjob.State -eq "Completed")
					{
						$wspStatus=Receive-Job -Name $checkWSPstatusjobname
						#Write-Host $wspStatus
						Remove-Job -Name $checkWSPstatusjobname
						break
					}
					elseif($checkWSPstatusjob.State -eq "Failed")
					{
						StatusUpdate("UNABLE TO GET THE STATUS OF THE WSP. PLEASE CHECK THE SOLUTION STORE AT $SolutionCA.")
						[System.Windows.Forms.Application]::DoEvents()
						return $false
					}
					else
					{
						StatusUpdate("Getting the status of wsp...please wait...")
						[System.Windows.Forms.Application]::DoEvents()
						Start-Sleep -Seconds 1
						continue
					}
				}
				if($wspStatus)
				{
					StatusUpdate("$wsp is present in the solution store. Continuing with the retraction and removal..")
					[System.Windows.Forms.Application]::DoEvents()
					$retractSolutionjobname="RetractSolution_"+(Get-Date -Format hh:mm:ss)
					$retractSolutionjobname=[string]$retractSolutionjobname
					$retractsolutionjob=Invoke-Command -Session $session -ScriptBlock {param($wsp);Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue;$solution=Get-SPSolution | Where-Object {($_.Name -eq $wsp)};if(!$solution.ContainsWebApplicationResource){Uninstall-SPSolution -identity $solution.SolutionId -Confirm:$false} else{Uninstall-SPSolution -identity $solution.SolutionId -AllWebApplications -Confirm:$false};while($solution.JobExists){Start-Sleep -Seconds 2};if($(Get-SPSolution | ? {$_.Name -eq $wsp}).Deployed -eq $false){Remove-SPSolution -identity $solution.SolutionId -Confirm:$false}} -ArgumentList $wsp -AsJob -JobName $retractSolutionjobname
					while($retractsolutionjob.State)
					{
						if($retractsolutionjob.State -eq "Completed")
						{
							StatusUpdate("Retraction and Removal of $wsp is complete. Checking if the WSP is still present in the store.")
							[System.Windows.Forms.Application]::DoEvents()
							$checkWSPstatusjobname="CheckWSPStatus_"+(Get-Date -Format hh:mm:ss)
							$checkWSPstatusjobname=[String]$checkWSPstatusjobname
							$checkWSPstatusjob=Invoke-Command -Session $session -ScriptBlock {param($wsp);Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ;$wspStatus=Get-SPSolution | Where-Object {$_.Name -eq $wsp};$wspStatus.Deployed} -ArgumentList $wsp -AsJob -JobName $checkWSPstatusjobname
							while($checkWSPstatusjob.State)
							{
								if($checkWSPstatusjob.State -eq "Completed")
								{
									$wspStatusAfterRetraction=Receive-Job -Name $checkWSPstatusjobname
									#Write-Host $wspStatusAfterRetraction
									Remove-Job -Name $checkWSPstatusjobname
									break
								}
								elseif($checkWSPstatusjob.State -eq "Failed")
								{
									StatusUpdate("FAILED GETTING THE STATUS OF THE WSP IN THE SOLUTION STORE. PLEASE CHECK MANUALLY AT $SolutionsCA ")
									[System.Windows.Forms.Application]::DoEvents()
									return $false
								}
								else
								{
									StatusUpdate("Getting the status of wsp...please wait...")
									[System.Windows.Forms.Application]::DoEvents()
									Start-Sleep -Seconds 1
									continue
								}
							}
							if($wspStatusAfterRetraction)
							{
								StatusUpdate("RETRACTION FAILED. $wsp IS STILL PRESENT IN THE FARM AFTER RETRACTION AND REMOVAL.PLEASE CHECK MANUALLY AT $SolutionsCA ")
								[System.Windows.Forms.Application]::DoEvents()
								return $false
							}
							else
							{
								StatusUpdate("Retraction Successful. $wsp is retracted and removed.")
								[System.Windows.Forms.Application]::DoEvents()
								break
							}
						}
						elseif($retractsolutionjob.State -eq "Failed")
						{
							StatusUpdate("RETRACT SOLUTIONS JOB FAILED. PLEASE CHECK MANUALLY AT $SolutionsCA .")
							[System.Windows.Forms.Application]::DoEvents()
							return $false
						}
						else
						{
							StatusUpdate("Retraction under progress..please wait..")
							[System.Windows.Forms.Application]::DoEvents()
							Start-Sleep -Seconds 4
							Continue
						}
					}
				}
				else
				{
					StatusUpdate("$wsp IS ABSENT IN THE SOLUTION STORE. CANNOT PROCEED WITH RETRACTION PROCEDURE. PLEASE CHECK MANUALLY AT $SolutionsCA ")
					[System.Windows.Forms.Application]::DoEvents()
					return $false
				}
			}
		}
		StatusUpdate("Retraction and Removal process complete")
		[System.Windows.Forms.Application]::DoEvents()
		return $true
	}
	function DeActivateFeature()
	{
		StatusUpdate("Loading Sharepoint Powershell snap-in and Deactivating Features...")
		[System.Windows.Forms.Application]::DoEvents()
		$jobname="ListFeaturesTxtFile_"+(Get-Date -Format hh:mm:ss)
		$jobname=[string]$jobname
		#Write-Host $jobname
		$joblistfeatures=Invoke-Command -Session $session -ScriptBlock {param($featurestxtfilepath) Get-Content -Path $featurestxtfilepath} -ArgumentList $featurestxtfilepath -AsJob -JobName $jobname
		while($joblistfeatures.State)
		{
			if($joblistfeatures.State -eq "Completed")
			{
				$listoffeatures=Receive-Job -Name $jobname
				break
			}
			elseif($joblistfeatures.State -eq "Failed")
			{
				StatusUpdate("UNABLE TO GET THE LIST OF FEATURES TO BE DEACTIVATED.")
				[System.Windows.Forms.Application]::DoEvents()
				return $false
			}
			else
			{
				StatusUpdate("Getting the list of features to be deactivated...please wait...")
				[System.Windows.Forms.Application]::DoEvents()
				Start-Sleep -Seconds 1
				continue
			}
		}	
		if($listoffeatures)
		{
			foreach($featureentry in $listoffeatures)
			{
				$featurearray=$featureentry.Split(",")
				$feature=$featurearray[0]
				$feature=[string]$feature
				if($featurearray[1])
				{
					$tempurl=$appurl
					$appurl=$featurearray[1]
				}
				#Write-Host $feature
				#Write-Host $appurl
				#write-host $tempurl
				StatusUpdate("Deactivating Feature $feature ...")
				[System.Windows.Forms.Application]::DoEvents()
				if($feature.Length -ge 1)
				{
					$jobname="DisableFeature_"+(Get-Date -Format hh:mm:ss)
					$jobname=[string]$jobname				
					$deactivatejob=Invoke-Command -Session $session -ScriptBlock{param($feature,$appurl) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; disable-spfeature -identity $feature -url $appurl -confirm:$false -force} -ArgumentList $feature,$appurl -AsJob -JobName $jobname
				}
				else
				{
					Continue
				}
				while($deactivatejob.State)
				{
					if($deactivatejob.State -eq "Completed")
					{
						StatusUpdate("Invoked the DeActivation command, checking if this is a success...")
						[System.Windows.Forms.Application]::DoEvents()
						Remove-Job $deactivatejob
						break
					}
					elseif($deactivatejob.State -eq "Failed")
					{
						StatusUpdate("DEACTIVATION JOB FAILED. PLEASE DEACTIVATE MANUALLY.")
						StatusUpdate("IF IT IS A SITECOLLECTION FEATURE, THE URL IS $appSCFeaturesURL")
						[System.Windows.Forms.Application]::DoEvents()
						return $false
					}
					else
					{
						StatusUpdate("Deactivating feature....please wait...")
						[System.Windows.Forms.Application]::DoEvents()
						Start-Sleep -Seconds 1
						Continue
					}
				}
				$scopejobname="GetScopeJob_"+(Get-Date -Format hh:mm:ss)
				$scopejobname=[string]$scopejobname
				$scopejob=Invoke-Command -Session $session -ScriptBlock{param($feature) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; (Get-SpFeature -Identity $feature).Scope} -ArgumentList $feature -AsJob -JobName $scopejobname
				while($scopejob.State)
				{
					if($scopejob.State -eq "Completed")
					{
						$scope=Receive-Job -Name $scopejobname
						Remove-Job $scopejobname
						break
					}
					elseif($scopejob.State -eq "Failed")
					{
						StatusUpdate("COULD NOT GET THE STATUS OF THE FEATURE AFTER DE-ACTIVATION. IF IT IS A SITECOLLECTION FEATURE, THE URL IS $appSCFeaturesURL")
						[System.Windows.Forms.Application]::DoEvents()
						return $false
					}
					else
					{
						StatusUpdate("Checking if the feature is deactivated...please wait...")
						[System.Windows.Forms.Application]::DoEvents()
						Start-Sleep -Seconds 1
						Continue
					}
				}
				$jobname="CheckFeature_"+(Get-Date -Format hh:mm:ss)
				$jobname=[string]$jobname
				$scope=[string]$scope
				#Write-Host $scope
				if(($scope -eq "Farm") -or ($scope -eq "0"))
				{
					StatusUpdate("Feature $feature is scoped to the Farm")
					[System.Windows.Forms.Application]::DoEvents()
					$checkfeaturejob=Invoke-Command -Session $session -ScriptBlock{param($feature) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; Get-SPFeature -Identity $feature -ErrorAction SilentlyContinue -Farm  } -ArgumentList $feature -AsJob -JobName $jobname
				}
				elseif(($scope -eq "WebApplication") -or ($scope -eq "1"))
				{
					StatusUpdate("Feature $feature is scoped to the WebApplication.")
					[System.Windows.Forms.Application]::DoEvents()
					$checkfeaturejob=Invoke-Command -Session $session -ScriptBlock{param($feature, $appurl) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; Get-SPFeature -Identity $feature -ErrorAction SilentlyContinue -WebApplication $appurl  } -ArgumentList $feature,$appurl -AsJob -JobName $jobname
				}
				elseif(($scope -eq "Site") -or ($scope -eq "2"))
				{
					StatusUpdate("Feature $feature is scoped to the SiteCollection.")
					[System.Windows.Forms.Application]::DoEvents()				
					$checkfeaturejob=Invoke-Command -Session $session -ScriptBlock{param($feature, $appurl) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; Get-SPFeature -Identity $feature -ErrorAction SilentlyContinue -Site $appurl  } -ArgumentList $feature,$appurl -AsJob -JobName $jobname
				}
				elseif(($scope -eq "Web") -or ($scope -eq "3"))
				{
					StatusUpdate("Feature $feature is scoped to the Site.")
					[System.Windows.Forms.Application]::DoEvents()		
					$checkfeaturejob=Invoke-Command -Session $session -ScriptBlock{param($feature, $appurl) Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ; Get-SPFeature -Identity $feature -ErrorAction SilentlyContinue -Web $appurl  } -ArgumentList $feature,$appurl -AsJob -JobName $jobname
				}
				else
				{
					StatusUpdate("COULD NOT GET THE SCOPE THE FEATURE TO VERIFY IF IT IS ACTIVATED. PLEASE CHECK MANUALLY $appSCFeaturesURL (Site collection features only)")
					[System.Windows.Forms.Application]::DoEvents()
					return $false
				}
				while($checkfeaturejob.State)
				{
					if($checkfeaturejob.State -eq "Completed")
					{
						$deactivatedfeaturecheck=Receive-Job -Name $jobname
						Remove-Job $checkfeaturejob
						break
					}
					elseif($checkfeaturejob.State -eq "Failed")
					{
						StatusUpdate("COULD NOT GET THE STATUS OF THE FEATURE AFTER DE-ACTIVATION. PLEASE CHECK MANUALLY $appSCFeaturesURL (Site collection features only)")
						[System.Windows.Forms.Application]::DoEvents()
						return $false
					}
					else
					{
						StatusUpdate("Checking if the feature is deactivated...please wait...")
						[System.Windows.Forms.Application]::DoEvents()
						Start-Sleep -Seconds 1
						Continue
					}
				}
				$deactivatedfeaturecheck=[string]$deactivatedfeaturecheck.DisplayName
				if($deactivatedfeaturecheck -eq "")
				{
					StatusUpdate("Feature $feature is deactivated successfully.")
					[System.Windows.Forms.Application]::DoEvents()
				}
				elseif($deactivatedfeaturecheck -eq $feature)
				{
					StatusUpdate("FEATURE $feature IS NOT DEACTIVATED.PLEASE CHECK MANUALLY $appSCFeaturesURL (Site collection features only)")
					[System.Windows.Forms.Application]::DoEvents()
					return $false
				}
				else
				{
					StatusUpdate("FEATURE THAT DIDNOT GET DEACTIVATED $feature .PLEASE CHECK MANUALLY $appSCFeaturesURL (Site collection features only)")
					StatusUpdate("$deactivatedfeaturecheck")
					[System.Windows.Forms.Application]::DoEvents()
					return $false
				}
			}
		}
		else
		{
			StatusUpdate("THE DEACTIVATION FEATURE FUNCTION DID NOT SUCCEED AS THERE ARE NO FEATURES LISTED IN THE FEATURES TXT FILE.")
			[System.Windows.Forms.Application]::DoEvents()
			return $false
		}
		$appurl=$tempurl
		#write-host $appurl
		return $true
	}
	Function StatusUpdate([string]$status)
	{
		log($status)
		$date=Get-Date
		$date=[string]$date
		$status=$status+"`r"
		$StatusUpdatebox1.Text=$date+"`t"+$status+"`n"+$StatusUpdatebox1.Text
	}
	function log([string]$logtext)
	{
		$a=Get-Date
	 	$a=[string]$a+"        "+$logtext
		if($Application -and $Environment -and $RFCNumber)
		{
			$filename=$Application+"_"+$EnvCombobox1.Text+"_"+$RFCNumber
			$date=Get-Date -Format M.d.yyyy
			$date=[string]$date
			$filename=$filename+"_"+$date+".txt"
			if(Test-Path -Path "$logspath\$filename")
			{
				$a >> "$logspath\$filename"
			}
			else
			{
				$a > "$logspath\$filename"
			}
		}
		
	}
	
	Function doValidations
	{
		StatusUpdate("Performing validations and checking the availabilty of the resources required for the deployment..")
		[System.Windows.Forms.Application]::DoEvents()
		$user=Get-WmiObject Win32_Computersystem -Comp "." | Select Name, UserName
		$user=[string]$user.Username
		StatusUpdate("This Deployment is being done by $user.")
		StatusUpdate("Checking if the servers of the farm are reachable...")
		[System.Windows.Forms.Application]::DoEvents()
		ForEach($farmserver in $servers)
		{
			$jobname=Get-Date -Format hh:mm:ss
			$jobname="PingServer_"+[string]$jobname
			$job=Start-Job -ScriptBlock {param($farmserver) Test-Connection $farmserver -Quiet -Count 2} -Name $jobname -ArgumentList $farmserver
			while($job.State)
			{
				if($job.State -eq "Completed")
				{
					$checkconnection=Receive-Job -Name $jobname
					break
				}
			}
			if ($checkconnection -eq $false)
			{
				StatusUpdate("THE SERVER $farmserver IS NOT REACHABLE.")
				[System.Windows.Forms.Application]::DoEvents()
				return $false
			}
			else 
			{
				StatusUpdate("$farmserver is reachable.")
				[System.Windows.Forms.Application]::DoEvents()
			}
			[System.Windows.Forms.Application]::DoEvents()
		}
		StatusUpdate("Done checking the servers.")
		[System.Windows.Forms.Application]::DoEvents()
		if(($checkboxActivateFeatures.Checked -ne $true) -and ($checkboxDeActivateFeatures.Checked -ne $true) -and ($checkboxDeploySolutions.Checked -ne $true) -and ($checkboxRetractSolutions.Checked -ne $true))
		{
			StatusUpdate("PLEASE CHECK ATLEAST ONE OPTION IN FEATURE ACTIVATION/DEACTIVATION AND WSP RETRACTION/DEPLOYMENT.")
			[System.Windows.Forms.Application]::DoEvents()
			Remove-PSSession -Session $session
			return $false
		}

		$global:securepassword=ConvertTo-SecureString -String $decryptedpassword -AsPlainText -Force
		$global:finalusername=$domain+"\"+$farmusername
		$global:crd=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $finalusername,$securepassword
		$global:session=New-PSSession -ComputerName $servers[0] -Authentication 'CredSSP' -Credential $crd
		StatusUpdate("Checking the presence of txt files and wsp files required for the deployment...")
		[System.Windows.Forms.Application]::DoEvents()
		if([string]$WSPtextbox1.Text -ne "" -and (($checkboxDeploySolutions.Checked -eq $true) -or (($checkboxRetractSolutions.Checked -eq $true) -and ($checkboxRetractUsingADiffere.Checked -eq $false))))
		{
			$global:wsptxtfilepath= [string]$WSPtextbox1.Text
			$wsptxtfilepath=[string]$wsptxtfilepath
			$checkWSPtxtfile=Invoke-Command -Session $session -ScriptBlock {param ($wsptxtfilepath) Test-Path -Path $wsptxtfilepath} -ArgumentList $wsptxtfilepath
			if($checkWSPtxtfile)
			{
				StatusUpdate("WSP Text file is present in the deployment base folder.")
				[System.Windows.Forms.Application]::DoEvents()
				$global:DeployWSPList=Invoke-Command -Session $session -ScriptBlock {param ($wsptxtfilepath) Get-Content -Path $wsptxtfilepath} -ArgumentList $wsptxtfilepath
				foreach($line in $DeployWSPList)
				{
					$wsp=$line.Split(",")
					$wsp=[string]$wsp[0]
					#Write-Host $wsp
					if($wsp.EndsWith(".wsp"))
					{
	
					}
					else
					{
						$wsp=$wsp+".wsp"
					}
					$wsppath=$deploymentwsppath+"\"+$wsp
					$wsppath=[string]$wsppath
					$checkWSPexists=Invoke-Command -Session $session -ScriptBlock {param ($wsppath) Test-Path -Path $wsppath} -ArgumentList $wsppath
					if($checkWSPexists)
					{
						$timestamp=Invoke-Command -Session $session -ScriptBlock {param ($wsppath) $(Get-Item -Path $wsppath).lastwritetime} -ArgumentList $wsppath
						StatusUpdate("$wsp is a WSP to be deployed and is present in the deployment base path with last modified time $timestamp")
						[System.Windows.Forms.Application]::DoEvents()
					}
					else
					{
						StatusUpdate("$wsp DOES NOT EXIST IN THE DEPLOYMENT BASE PATH $deploymentwsppath OF THE SERVER")
						[System.Windows.Forms.Application]::DoEvents()
						Remove-PSSession -Session $session
						return $false
					}
				}
			}
			else
			{
				StatusUpdate("$wsptxtfilepath TEXT FILE IS ABSENT ON THE SERVER OR THE PATH IS INVALID")
				[System.Windows.Forms.Application]::DoEvents()
				Remove-PSSession -Session $session
				return $false
			}
		}
		else
		{
			StatusUpdate("No retraction and deployment of wsps is selected.")
			[System.Windows.Forms.Application]::DoEvents()
		}
		if(($checkboxRetractUsingADiffere.Checked -eq $true) -and ([string]$RetractWSPtextbox1.Text -ne ""))
		{
			$global:retractwsptxtfilepath=[string]$RetractWSPtextbox1.Text
			$checkretractwsppath=Invoke-Command -Session $session -ScriptBlock {param ($retractwsptxtfilepath) Test-Path -Path $retractwsptxtfilepath} -ArgumentList $retractwsptxtfilepath
			if($checkretractwsppath)
			{
				StatusUpdate("Retract WSP Text file is present in the deployment base path directory and $retractwsptxtfilepath will be used for retraction.")
				[System.Windows.Forms.Application]::DoEvents()
			}
			else
			{
				StatusUpdate("$retractwsptxtfilepath TEXT FILE IS ABSENT ON THE SERVER")
				[System.Windows.Forms.Application]::DoEvents()
				Remove-PSSession -Session $session
				return $false
			}
		}
		if(($checkboxDeActivateFeatures.Checked -eq $true) -or ($checkboxActivateFeatures.Checked -eq $true))
		{
			$global:featurestxtfilepath=[string]$Featuretextbox1.Text
			[string]$featurestxtfilepath=$featurestxtfilepath
			$checkfeaturestxtfilepath=Invoke-Command -Session $session -ScriptBlock {param($featurestxtfilepath) Test-Path -Path $featurestxtfilepath} -ArgumentList $featurestxtfilepath
			if($checkfeaturestxtfilepath)
			{
				StatusUpdate("The Features text file is present in the deployment base path directory $featurestxtfilepath")
				[System.Windows.Forms.Application]::DoEvents()
			}
			else
			{
				StatusUpdate("$featurestxtfilepath IS ABSENT ON THE SERVER.")
				[System.Windows.Forms.Application]::DoEvents()
				Remove-PSSession -Session $session
				return $false
			}
		}
		return $true
	}
	
	$EnvCombobox1_SelectedIndexChanged={
		$config=[xml](Get-Content -Path ".\config.xml")
		$AppNameCombobox1.Items.Clear()
		ForEach($environment in $config.SHAREPOINT_CONFIGURATION.ENVIRONMENT|Where-Object{$_.EnvName -eq $EnvCombobox1.Text}) 
		{
			foreach($appname in $environment.APPLICATION.NAME)
			{
				#StatusUpdate("Selected Environment is "+$environment.EnvName)
				$AppNameCombobox1.Items.Add($appname.AppName)
			}
		}
	}
	
	# --End User Generated Script--
	#----------------------------------------------
	#region Generated Events
	#----------------------------------------------
	
	$Form_StateCorrection_Load=
	{
		#Correct the initial state of the form to prevent the .Net maximized form issue
		$formSharepointDeployerV3.WindowState = $InitialFormWindowState
	}
	
	$Form_Cleanup_FormClosed=
	{
		#Remove all event handlers from the controls
		try
		{
			$buttonDeploy.remove_Click($buttonDeploy_Click)
			$EnvCombobox1.remove_SelectedIndexChanged($EnvCombobox1_SelectedIndexChanged)
			$buttonApplyConfig.remove_Click($buttonApplyConfig_Click)
			$formSharepointDeployerV3.remove_Load($formSharepointDeployerV3_Load)
			$formSharepointDeployerV3.remove_Load($Form_StateCorrection_Load)
			$formSharepointDeployerV3.remove_FormClosed($Form_Cleanup_FormClosed)
		}
		catch [Exception]
		{ }
	}
	#endregion Generated Events

	#----------------------------------------------
	#region Generated Form Code
	#----------------------------------------------
	#
	# formSharepointDeployerV3
	#
	$formSharepointDeployerV3.Controls.Add($groupbox2)
	$formSharepointDeployerV3.Controls.Add($groupbox1)
	$formSharepointDeployerV3.Controls.Add($labelSharepointDeployer)
	$formSharepointDeployerV3.Controls.Add($RFCInputbox1)
	$formSharepointDeployerV3.ClientSize = '695, 616'
	$formSharepointDeployerV3.Font = "Microsoft Sans Serif, 8.25pt, style=Bold"
	$formSharepointDeployerV3.FormBorderStyle = 'FixedSingle'
	#region Binary Data
	$formSharepointDeployerV3.Icon = [System.Convert]::FromBase64String('AAABAAEAICAAAAAAIABbAQAAFgAAAIlQTkcNChoKAAAADUlIRFIAAAAgAAAAIAgGAAAAc3p69AAA
AAlwSFlzAAALEwAACxMBAJqcGAAAAQ1JREFUWIXFl00SgjAMRsNML4B7vQFr77907Q10j0eAhVP9
rGmTtknJip/Ce2mBhImUMS/rhvuv+2nSXluK4k28oKqYl3VLBTziLyOEDs04wkdkjfHJMIJbs36c
r0Xxy/PG3nfqhSM4BxHH9Ey7lHk6lh0/SiArMVKAleh5+lsE8LpA9H74osTodz/EDZTAY8MEUiC3
LB5CIXcihXktUVaAE8JZsRJRCyDUcjaqBFDEqmg1CfQGfjsOESD6FqUmAcueoVrg0LfAAp7WDrWA
ZebYlIgC3rWhKGC93lzpZgW0WWt7gVJP+CPQMt25RjSF58YFz5IrwYmgI7KC1sCJiIJHxjEkOJHw
d1wL1EIxdl3czCs6sgT5AAAAAElFTkSuQmCC')
	#endregion
	$formSharepointDeployerV3.MaximizeBox = $False
	$formSharepointDeployerV3.Name = "formSharepointDeployerV3"
	$formSharepointDeployerV3.Text = "Sharepoint Solution Deployer V3.2"
	$formSharepointDeployerV3.add_Load($formSharepointDeployerV3_Load)
	#
	# groupbox2
	#
	$groupbox2.Controls.Add($StatusUpdatebox1)
	$groupbox2.Location = '60, 408'
	$groupbox2.Name = "groupbox2"
	$groupbox2.Size = '573, 204'
	$groupbox2.TabIndex = 3
	$groupbox2.TabStop = $False
	$groupbox2.Text = "Status"
	#
	# StatusUpdatebox1
	#
	$StatusUpdatebox1.Font = "Microsoft Sans Serif, 8.25pt"
	$StatusUpdatebox1.Location = '0, 19'
	$StatusUpdatebox1.Multiline = $True
	$StatusUpdatebox1.Name = "StatusUpdatebox1"
	$StatusUpdatebox1.ReadOnly = $True
	$StatusUpdatebox1.ScrollBars = 'Both'
	$StatusUpdatebox1.Size = '573, 183'
	$StatusUpdatebox1.TabIndex = 0
	#
	# groupbox1
	#
	$groupbox1.Controls.Add($RetractWSPtextbox1)
	$groupbox1.Controls.Add($checkboxRetractUsingADiffere)
	$groupbox1.Controls.Add($buttonDeploy)
	$groupbox1.Controls.Add($checkboxTimerServiceRestart)
	$groupbox1.Controls.Add($checkboxIISReset)
	$groupbox1.Controls.Add($checkboxConfigFileChanges)
	$groupbox1.Controls.Add($checkboxActivateFeatures)
	$groupbox1.Controls.Add($checkboxDeploySolutions)
	$groupbox1.Controls.Add($checkboxRetractSolutions)
	$groupbox1.Controls.Add($checkboxDeActivateFeatures)
	$groupbox1.Controls.Add($WSPtextbox1)
	$groupbox1.Controls.Add($Featuretextbox1)
	$groupbox1.Controls.Add($labelReadingTheWSPDetails)
	$groupbox1.Controls.Add($labelReadingTheFeatureDet)
	$groupbox1.Enabled = $False
	$groupbox1.Font = "Microsoft Sans Serif, 8.25pt, style=Bold"
	$groupbox1.Location = '60, 200'
	$groupbox1.Name = "groupbox1"
	$groupbox1.Size = '573, 202'
	$groupbox1.TabIndex = 2
	$groupbox1.TabStop = $False
	$groupbox1.Text = "Applied Configuration"
	#
	# RetractWSPtextbox1
	#
	$RetractWSPtextbox1.Font = "Microsoft Sans Serif, 8.25pt"
	$RetractWSPtextbox1.Location = '183, 88'
	$RetractWSPtextbox1.Name = "RetractWSPtextbox1"
	$RetractWSPtextbox1.Size = '348, 20'
	$RetractWSPtextbox1.TabIndex = 14
	#
	# checkboxRetractUsingADiffere
	#
	$checkboxRetractUsingADiffere.Font = "Microsoft Sans Serif, 8.25pt"
	$checkboxRetractUsingADiffere.Location = '15, 85'
	$checkboxRetractUsingADiffere.Name = "checkboxRetractUsingADiffere"
	$checkboxRetractUsingADiffere.Size = '172, 27'
	$checkboxRetractUsingADiffere.TabIndex = 13
	$checkboxRetractUsingADiffere.Text = "Retract using a different file - "
	$checkboxRetractUsingADiffere.UseVisualStyleBackColor = $True
	#
	# buttonDeploy
	#
	$buttonDeploy.Location = '434, 151'
	$buttonDeploy.Name = "buttonDeploy"
	$buttonDeploy.Size = '97, 44'
	$buttonDeploy.TabIndex = 11
	$buttonDeploy.Text = "Deploy"
	$buttonDeploy.UseVisualStyleBackColor = $True
	$buttonDeploy.add_Click($buttonDeploy_Click)
	#
	# checkboxTimerServiceRestart
	#
	$checkboxTimerServiceRestart.Font = "Microsoft Sans Serif, 8.25pt"
	$checkboxTimerServiceRestart.Location = '434, 119'
	$checkboxTimerServiceRestart.Name = "checkboxTimerServiceRestart"
	$checkboxTimerServiceRestart.Size = '129, 27'
	$checkboxTimerServiceRestart.TabIndex = 10
	$checkboxTimerServiceRestart.Text = "Timer Service Restart"
	$checkboxTimerServiceRestart.UseVisualStyleBackColor = $True
	#
	# checkboxIISReset
	#
	$checkboxIISReset.Checked = $True
	$checkboxIISReset.CheckState = 'Checked'
	$checkboxIISReset.Font = "Microsoft Sans Serif, 8.25pt"
	$checkboxIISReset.Location = '300, 119'
	$checkboxIISReset.Name = "checkboxIISReset"
	$checkboxIISReset.Size = '87, 27'
	$checkboxIISReset.TabIndex = 9
	$checkboxIISReset.Text = "IIS Reset"
	$checkboxIISReset.UseVisualStyleBackColor = $True
	#
	# checkboxConfigFileChanges
	#
	$checkboxConfigFileChanges.Font = "Microsoft Sans Serif, 8.25pt"
	$checkboxConfigFileChanges.Location = '300, 169'
	$checkboxConfigFileChanges.Name = "checkboxConfigFileChanges"
	$checkboxConfigFileChanges.Size = '127, 27'
	$checkboxConfigFileChanges.TabIndex = 8
	$checkboxConfigFileChanges.Text = "Config File Changes"
	$checkboxConfigFileChanges.UseVisualStyleBackColor = $True
	#
	# checkboxActivateFeatures
	#
	$checkboxActivateFeatures.Checked = $True
	$checkboxActivateFeatures.CheckState = 'Checked'
	$checkboxActivateFeatures.Font = "Microsoft Sans Serif, 8.25pt"
	$checkboxActivateFeatures.Location = '17, 168'
	$checkboxActivateFeatures.Name = "checkboxActivateFeatures"
	$checkboxActivateFeatures.Size = '127, 27'
	$checkboxActivateFeatures.TabIndex = 7
	$checkboxActivateFeatures.Text = "Activate Features"
	$checkboxActivateFeatures.UseVisualStyleBackColor = $True
	#
	# checkboxDeploySolutions
	#
	$checkboxDeploySolutions.Checked = $True
	$checkboxDeploySolutions.CheckState = 'Checked'
	$checkboxDeploySolutions.Font = "Microsoft Sans Serif, 8.25pt"
	$checkboxDeploySolutions.Location = '171, 169'
	$checkboxDeploySolutions.Name = "checkboxDeploySolutions"
	$checkboxDeploySolutions.Size = '127, 27'
	$checkboxDeploySolutions.TabIndex = 6
	$checkboxDeploySolutions.Text = "Deploy Solutions"
	$checkboxDeploySolutions.UseVisualStyleBackColor = $True
	#
	# checkboxRetractSolutions
	#
	$checkboxRetractSolutions.Checked = $True
	$checkboxRetractSolutions.CheckState = 'Checked'
	$checkboxRetractSolutions.Font = "Microsoft Sans Serif, 8.25pt"
	$checkboxRetractSolutions.Location = '171, 119'
	$checkboxRetractSolutions.Name = "checkboxRetractSolutions"
	$checkboxRetractSolutions.Size = '127, 27'
	$checkboxRetractSolutions.TabIndex = 5
	$checkboxRetractSolutions.Text = "Retract Solutions"
	$checkboxRetractSolutions.UseVisualStyleBackColor = $True
	#
	# checkboxDeActivateFeatures
	#
	$checkboxDeActivateFeatures.Checked = $True
	$checkboxDeActivateFeatures.CheckState = 'Checked'
	$checkboxDeActivateFeatures.Font = "Microsoft Sans Serif, 8.25pt"
	$checkboxDeActivateFeatures.Location = '17, 117'
	$checkboxDeActivateFeatures.Name = "checkboxDeActivateFeatures"
	$checkboxDeActivateFeatures.Size = '127, 27'
	$checkboxDeActivateFeatures.TabIndex = 4
	$checkboxDeActivateFeatures.Text = "De-activate Features"
	$checkboxDeActivateFeatures.UseVisualStyleBackColor = $True
	#
	# WSPtextbox1
	#
	$WSPtextbox1.Font = "Microsoft Sans Serif, 8.25pt"
	$WSPtextbox1.Location = '183, 53'
	$WSPtextbox1.Name = "WSPtextbox1"
	$WSPtextbox1.Size = '348, 20'
	$WSPtextbox1.TabIndex = 3
	#
	# Featuretextbox1
	#
	$Featuretextbox1.Font = "Microsoft Sans Serif, 8.25pt"
	$Featuretextbox1.Location = '183, 20'
	$Featuretextbox1.Name = "Featuretextbox1"
	$Featuretextbox1.Size = '348, 20'
	$Featuretextbox1.TabIndex = 2
	#
	# labelReadingTheWSPDetails
	#
	$labelReadingTheWSPDetails.Font = "Microsoft Sans Serif, 8.25pt"
	$labelReadingTheWSPDetails.Location = '17, 55'
	$labelReadingTheWSPDetails.Name = "labelReadingTheWSPDetails"
	$labelReadingTheWSPDetails.Size = '170, 23'
	$labelReadingTheWSPDetails.TabIndex = 1
	$labelReadingTheWSPDetails.Text = "Reading the WSP details from - "
	#
	# labelReadingTheFeatureDet
	#
	$labelReadingTheFeatureDet.Font = "Microsoft Sans Serif, 8.25pt"
	$labelReadingTheFeatureDet.Location = '6, 22'
	$labelReadingTheFeatureDet.Name = "labelReadingTheFeatureDet"
	$labelReadingTheFeatureDet.Size = '181, 23'
	$labelReadingTheFeatureDet.TabIndex = 0
	$labelReadingTheFeatureDet.Text = "Reading the Feature details from - "
	#
	# labelSharepointDeployer
	#
	$labelSharepointDeployer.Font = "Tahoma, 19pt, style=Bold"
	$labelSharepointDeployer.ForeColor = 'DarkBlue'
	$labelSharepointDeployer.Location = '188, 0'
	$labelSharepointDeployer.Name = "labelSharepointDeployer"
	$labelSharepointDeployer.Size = '400, 40'
	$labelSharepointDeployer.TabIndex = 1
	$labelSharepointDeployer.Text = "Sharepoint Solution Deployer"
	#
	# RFCInputbox1
	#
	$RFCInputbox1.Controls.Add($labelSelectTheEnvironment)
	$RFCInputbox1.Controls.Add($EnvCombobox1)
	$RFCInputbox1.Controls.Add($buttonApplyConfig)
	$RFCInputbox1.Controls.Add($labelSelectTheApplication)
	$RFCInputbox1.Controls.Add($labelPleaseProvideRFCNumb)
	$RFCInputbox1.Controls.Add($AppNameCombobox1)
	$RFCInputbox1.Controls.Add($CRNumbox1)
	$RFCInputbox1.Font = "Microsoft Sans Serif, 8.25pt, style=Bold"
	$RFCInputbox1.Location = '60, 48'
	$RFCInputbox1.Name = "RFCInputbox1"
	$RFCInputbox1.Size = '573, 145'
	$RFCInputbox1.TabIndex = 0
	$RFCInputbox1.TabStop = $False
	$RFCInputbox1.Text = "Input Details"
	#
	# labelSelectTheEnvironment
	#
	$labelSelectTheEnvironment.Font = "Microsoft Sans Serif, 8.25pt"
	$labelSelectTheEnvironment.Location = '30, 68'
	$labelSelectTheEnvironment.Name = "labelSelectTheEnvironment"
	$labelSelectTheEnvironment.Size = '137, 23'
	$labelSelectTheEnvironment.TabIndex = 6
	$labelSelectTheEnvironment.Text = "Select the Environment *"
	#
	# EnvCombobox1
	#
	$EnvCombobox1.DropDownStyle = 'DropDownList'
	$EnvCombobox1.Font = "Microsoft Sans Serif, 8.25pt"
	$EnvCombobox1.FormattingEnabled = $True
	$EnvCombobox1.Location = '171, 65'
	$EnvCombobox1.Name = "EnvCombobox1"
	$EnvCombobox1.Size = '190, 21'
	$EnvCombobox1.TabIndex = 5
	$EnvCombobox1.add_SelectedIndexChanged($EnvCombobox1_SelectedIndexChanged)
	#
	# buttonApplyConfig
	#
	$buttonApplyConfig.Location = '434, 57'
	$buttonApplyConfig.Name = "buttonApplyConfig"
	$buttonApplyConfig.Size = '97, 37'
	$buttonApplyConfig.TabIndex = 4
	$buttonApplyConfig.Text = "Apply Config"
	$buttonApplyConfig.UseVisualStyleBackColor = $True
	$buttonApplyConfig.add_Click($buttonApplyConfig_Click)
	#
	# labelSelectTheApplication
	#
	$labelSelectTheApplication.Font = "Microsoft Sans Serif, 8.25pt"
	$labelSelectTheApplication.Location = '36, 113'
	$labelSelectTheApplication.Name = "labelSelectTheApplication"
	$labelSelectTheApplication.Size = '127, 23'
	$labelSelectTheApplication.TabIndex = 3
	$labelSelectTheApplication.Text = "Select the Application *"
	#
	# labelPleaseProvideRFCNumb
	#
	$labelPleaseProvideRFCNumb.Font = "Microsoft Sans Serif, 8.25pt"
	$labelPleaseProvideRFCNumb.Location = '6, 25'
	$labelPleaseProvideRFCNumb.Name = "labelPleaseProvideRFCNumb"
	$labelPleaseProvideRFCNumb.Size = '160, 23'
	$labelPleaseProvideRFCNumb.TabIndex = 2
	$labelPleaseProvideRFCNumb.Text = "Please provide RFC Number *"
	#
	# AppNameCombobox1
	#
	$AppNameCombobox1.DropDownStyle = 'DropDownList'
	$AppNameCombobox1.Font = "Microsoft Sans Serif, 8.25pt"
	$AppNameCombobox1.FormattingEnabled = $True
	$AppNameCombobox1.Location = '171, 111'
	$AppNameCombobox1.Name = "AppNameCombobox1"
	$AppNameCombobox1.Size = '190, 21'
	$AppNameCombobox1.TabIndex = 1
	#
	# CRNumbox1
	#
	$CRNumbox1.Font = "Microsoft Sans Serif, 8.25pt"
	$CRNumbox1.Location = '171, 23'
	$CRNumbox1.Name = "CRNumbox1"
	$CRNumbox1.Size = '190, 20'
	$CRNumbox1.TabIndex = 0
	#endregion Generated Form Code

	#----------------------------------------------

	#Save the initial state of the form
	$InitialFormWindowState = $formSharepointDeployerV3.WindowState
	#Init the OnLoad event to correct the initial state of the form
	$formSharepointDeployerV3.add_Load($Form_StateCorrection_Load)
	#Clean up the control events
	$formSharepointDeployerV3.add_FormClosed($Form_Cleanup_FormClosed)
	#Show the Form
	return $formSharepointDeployerV3.ShowDialog()

} #End Function

#Call OnApplicationLoad to initialize
if((OnApplicationLoad) -eq $true)
{
	#Call the form
	Call-SharepointDeployer_pff | Out-Null
	#Perform cleanup
	OnApplicationExit
}
#------------------------------------------------------------------------
#SHAREPOINT DEPLOYER V3 - DEVELOPED BY VENKATA HAREESH SANAGAVARAPU (harishmeetsu@gmail.com)
#----------------------------------------------